package com.wantupai.translate;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;

import com.jianjin.camera.CustomCameraAgent;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.xutils.x;

import java.util.LinkedList;

/**
 * @author luxuchang
 * @date 2019/4/23 0023
 * @description
 */
public class App extends Application {
    private static IWXAPI mWeChatApi;

    /**
     * 应用的登录状态
     */
    public static boolean isLogin = false;
    /**
     * 全局的上下文
     */
    private static App instance = null;

    /**
     * 所有activity的集合列表
     */
    private LinkedList<Activity> activitys = new LinkedList<>();

    /**
     * 获取应用对象
     *
     * @return 应用是实例
     */
    public static App getInstance() {
        return instance;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        /**
         * Multidex突破64K方法数限制
         */
//        MultiDex.install(this);
    }


    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        CustomCameraAgent.init(this);
        x.Ext.init(this);

        mWeChatApi = WXAPIFactory.createWXAPI(this, Constant.WECHAT_APPID, true);
        mWeChatApi.registerApp(Constant.WECHAT_APPID);

        //防止拍照崩溃
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
    }

    public static IWXAPI getWeChatApi() {
        return mWeChatApi;
    }


    @Override
    public void onLowMemory() {
        super.onLowMemory();
        System.gc();
    }

    /**
     * 添加activity到LinkedList集合
     *
     * @param activity
     */
    public void addActivityList(Activity activity) {
        activitys.add(activity);
    }

    /**
     * 移除当前的页面
     *
     * @param activity
     */
    public void removeActivity(Activity activity) {
        activitys.remove(activity);
    }
}
